<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form th:action="@{/supplier/list}" method="get">
    <div id="box">
        <h2>北大青鸟合作供应商联系人</h2>
        <input type="text" name="cname">
        <select name="pid" id="pid">
            <option value="0" selected>--请选择--</option>
            <span th:each="all : ${all}">
                <option th:text="${all.sname}" th:value="${all.id}"></option>
            </span>
        </select>

        <input type="submit" value="查询">
        <input type="button" th:onclick="'location.href=\'/supplier/toAdd\''" value="添加供应商联系人"/>
    </div>
</form>

<table border="1">
    <tr>
        <td>供应商联系人编号</td>
        <td>供应商联系人姓名</td>
        <td>供应商联系人年龄</td>
        <td>供应商联系人手机</td>
        <td>所属供应商</td>
        <td>创建日期</td>
        <td>操作</td>
    </tr>

    <tr th:each=" supplierContact : ${list}">
        <td>[[${supplierContact.id}]]</td>
        <td>[[${supplierContact.cname}]]</td>
        <td>[[${supplierContact.age}]]</td>
        <td>[[${supplierContact.mobile}]]</td>
        <td>
            <span th:if="${supplierContact.pid == 3}">小米</span>
            <span th:if="${supplierContact.pid == 4}">腾讯</span>
            <span th:if="${supplierContact.pid == 5}">百度</span>
        </td>
        <td th:text="${#dates.format(supplierContact.createdate,'yyyy-MM-dd')}"></td>
        <td>
            <a href="javascript:void(0)" th:onclick="'del('+${supplierContact.id}+')'">删除</a>
            <a href="javascript:void(0)" th:onclick="'location.href=\'/supplier/byId?id='+${supplierContact.id}+'\''">修改</a>
        </td>
    </tr>


</table>


<script src="/js/jquery.js"></script>
<script>
    $(function () {
        $("tr:odd").css("background-color", "#fff")
        $("tr:even").css("background-color", "aquamarine")
        $("tr:eq(0)").css("background-color", "aqua")
    })

    function del(id) {
        if (confirm("确定要删除吗？")) {
            $.post('delete', {id: id}, function (data) {
                if (data) {
                    alert("删除成功！");
                    location.href = 'list';
                } else {
                    alert("删除失败！");
                }
            })
        }
    }


</script>

</body>
</html>